package 最长回文子序列;

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    static int N = 1010;
    static int[][] f = new int[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int n = s.length();
        for (int i = 1; i <= n; i++) {
            f[i][i] = 1;
        }
        for (int i = 1; i < n; i++) {
            if (s.charAt(i - 1) == s.charAt(i)) {
                f[i + 1][i] = f[i][i + 1] = 2;
            }else {
                f[i + 1][i] = f[i][i + 1] = 1;
            }
        }
        for (int d = 3; d <= n; d++) {
            for (int l = 1; l + d - 1 <= n; l++) {
                int r = l + d - 1;
                if (s.charAt(l - 1) == s.charAt(r - 1)) {
                    f[l][r] = f[l + 1][r - 1] + 2;
                } else {
                    f[l][r] = Math.max(f[l][r - 1], f[l + 1][r]);
                }
            }
        }
        System.out.println(f[1][n]);
    }
}